﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkCard.Utils;
using LinkCard.Model;

namespace LinkCard.CustomerView.CusCp
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            error.Visible = false;
        }

        private void ChangePass()
        {
            var sOldPasss = this.oldPass.Value.Trim();
            var sNewPass = this.newPassword.Value.Trim();
            Int64 _id = Convert.ToInt64(Session["USERID"].ToString());

            //Session["USER"] = sUsername;
            //Session["USERID"] = _customer.CustomerID;
            //Session.Timeout = 19;
            //Response.Redirect("transaction_report.aspx");

            var db = new TopLinkEntities();

            var _user = db.Customers.Where(t => t.CustomerID == _id).FirstOrDefault();
            if (_user != null)
            {
                if (_user.Password == sOldPasss)
                {
                    _user.Password = sNewPass;

                    db.SaveChanges();

                    Response.Redirect("/CusCp/message_box.aspx?msg=2");
                }
                else
                {
                    error.Visible = true;
                }
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ChangePass();
        }
    }
}